from itsdangerous import TimedJSONWebSignatureSerializer as TJSWSSerializer
# 加密方法
def generate_sign_openid(openid):

    serializer = TJSWSSerializer(secret_key="oauth", expires_in=300)

    sign_openid = serializer.dumps({"openid": openid})

    return sign_openid.decode()


# 解密方法
def decode_sign_openid(data):
    serializer = TJSWSSerializer(secret_key="oauth", expires_in=300)
    try:
        data_dict = serializer.loads(data)
    except Exception as e:
        return None

    return data_dict.get("openid")

